<!-- 测试用户API的简单页面 -->
<template>
  <div class="test-container">
    <h2>用户API测试</h2>
    
    <div class="test-section">
      <h3>获取用户信息</h3>
      <el-button @click="testGetUser" :loading="loading">测试获取用户信息</el-button>
      
      <div v-if="userInfo" class="result">
        <h4>API返回结果：</h4>
        <pre>{{ JSON.stringify(userInfo, null, 2) }}</pre>
      </div>
      
      <div v-if="error" class="error">
        <h4>错误信息：</h4>
        <p>{{ error }}</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { getUserDetails } from '@/api/user'
import { ElMessage } from 'element-plus'

const loading = ref(false)
const userInfo = ref(null)
const error = ref('')

const testGetUser = async () => {
  loading.value = true
  error.value = ''
  userInfo.value = null
  
  try {
    const data = await getUserDetails(1) // 测试用户ID为1
    userInfo.value = data
    ElMessage.success('获取用户信息成功')
  } catch (err) {
    error.value = err.message
    ElMessage.error('获取用户信息失败: ' + err.message)
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.test-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.test-section {
  margin: 20px 0;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
}

.result {
  margin-top: 20px;
  padding: 15px;
  background-color: #f0f9ff;
  border-radius: 4px;
}

.error {
  margin-top: 20px;
  padding: 15px;
  background-color: #fef2f2;
  border-radius: 4px;
  color: #dc2626;
}

pre {
  white-space: pre-wrap;
  word-wrap: break-word;
}
</style>